﻿<HTML>
<HEAD><TITLE>后台管理系统</TITLE>

    <META http-equiv=Content-Type content="text/html; charset=utf-8">
    <META content="Microsoft FrontPage 4.0" name=GENERATOR>

    <script src="__FINANCE__/Scripts/jquery.js" charset="utf-8"></script>
    <script src="__FINANCE__/Scripts/watermarker.js" charset="utf-8"></script>
    <link href="__FINANCE__/layui/css/layui.css" rel='stylesheet' type='text/css'/>
    <script src="__FINANCE__/layui/layui.js" charset="utf-8"></script>
    <!--<script src="__FINANCE__/layer/layer.js" charset="utf-8"></script>-->

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /* 偶数行背景色 */
        .layui-table[lay-even] tr:nth-child(even) {
            /* background-color: #aaffaa; */
            background-color: #eeffee;
        }

        /* 鼠标指向表格时,奇数行背景颜色 */
        .layui-table tbody tr:hover,.layui-table-hover {
            background-color:  #abd1f9;
        }

        /*!* 表格头部工具栏背景色 *!*/
        /*.layui-table-tool {*/
        /*background-color: #eeffee;*/
        /*}*/

        /* 表格头部背景色 */
        /*th {*/
        /*background-color: #359f6a; !* MediumSeaGreen *!*/
        /*color: #fff;*/
        /*font-weight: bold*/
        /*}*/
    </style>
</HEAD>
<body>
{if session('user_name') == 'admin' }
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>

        <td width="68%" background="__FINANCE__/Images/b2.jpg">
            <table width="124" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="20" align="left"><img src="__FINANCE__/Picture/tz.gif" width="10" height="16"/></td>
                    <td width="104" align="left" class="biao">查询条件</td>
                </tr>
            </table>
        </td>

    </tr>
</table>
<blockquote class="layui-elem-quote layui-quote-nm" style="margin-bottom: 0px;padding:0px;padding-top: 10px">
    <div class="layui-form-item">
        <form class="layui-form" id="form1" name="form1" method="get" action="">
            <table width="100%" border="0" cellspacing="1" cellpadding="3">
                <tr align="center">
                    <!--<td width="3%">工资年份：</td>-->
                    <!--<td width="5%"><label>-->
                        <!--<div class="layui-input-inline">-->
                            <!--<div class="layui-input-inline">-->
                                <!--<input type="text" name="date_time" id="date_time"  placeholder=""-->
                                       <!--autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</label></td>-->
                    <td align="center" width="2%">姓名：</td>
                    <td width="5%">
                        <div class="layui-input-inline">
                            <input type="tel" name="name" id="name" autocomplete="off"
                                   class="layui-input">
                        </div>
                    <td align="center" width="3%">身份证号：</td>
                    <td align="center" width="10%">
                        <input type="text" name="card_num" id="card_num"  placeholder="" autocomplete="off"
                               class="layui-input">
                    </td>
                    <td width="10%">
                        <div class="layui-input-block">
                            <button type="button" id="search-input" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">
                                <i class="layui-icon">&#xe615;</i>查询
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</blockquote>
{/if}
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td width="68%" background="__FINANCE__/Images/b2.jpg">
            <table width="124" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="20" align="left"><img src="__FINANCE__/Picture/tz.gif" width="10" height="16"/></td>
                    <td width="104" align="left" class="biao">数据列表</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<table class="layui-hide" id="salary_bak_list" lay-filter="salary_bak_list"></table>
<script type="text/html" id="salary_bak_list_toolbar">
    <div class="layui-btn-container">
        {if session('user_name') == 'admin' }
        <!--<button type="button"  class="layui-btn layui-btn-warm" id="add_salary_back" lay-event="add_salary_back"><i class="layui-icon">&#xe654;</i>添加</button>-->
        <button type="button"  class="layui-btn" id="uploadExcel"><i class="layui-icon">&#xe67c;</i>导入</button>
        <button type="button" class="layui-btn layui-btn-normal" id="exportExcel" lay-event="exportExcel"><i class="layui-icon">&#xe601;</i>导出</button>
        <button type="button" class="layui-btn layui-btn-danger" id="deletes" lay-event="deletes"><i class="layui-icon">&#xe640;</i>删除</button>
        {/if}
    </div>
</script>
<script>
    watermark({watermark_txt:'新乡市纪委监委财务管理'});
    layui.use(['table', 'upload','laydate'], function () {
        var table = layui.table
            ,$ = layui.jquery
           , layer = layui.layer
            , laydate = layui.laydate
            , upload = layui.upload;
        //日期
        laydate.render({
            elem: '#date_time'
            , type: 'month'
        });

        var tableIns = table.render({
            elem: '#salary_bak_list'
            , url: '{:url("/finance/SalaryBack/ajaxSalaryBackChaXun")}'
            , toolbar: '#salary_bak_list_toolbar'
            ,defaultToolbar: ['filter']
            , title: '用户数据表'
            , totalRow: true
            ,height:500
            ,limit:15
            ,limits:[15, 30, 45, 60, 80,100]
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
//                , {field: 'id', title: 'id', width: 60, fixed: 'left', sort: true, totalRowText: '合计'}
//                , {field: 'department', title: '部门', width: 80}
                , {field: 'user_name', title: '人员名称', width: 150,}
                , {field: 'reasons_for_increas', title: '增（减）原因', width: 150,}
                , {field: 'reasons_time', title: '增（减）时间', width: 120,totalRowText: '合计',}
                , {field: 'monthly_salary_increase', title: '月工资增（减）额', width: 150,totalRow: true}
                , {field: 'replacement_months', title: '补发月数', width: 100,}
                , {field: 'salary_bak', title: '本月补发工资', width: 120,totalRow: true,}
                , {field: 'deduct_more_amount', title: '扣减多发金额', width: 120,totalRow: true}
                , {field: 'remark', title: '备注',}
            ]]
            , page: true
        });
        //工具栏事件
        table.on('toolbar(salary_bak_list)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add_salary_back':
                    $.ajax({
                        url: '{:url("/finance/Salaryback/addSalaryBack")}',
                        type: 'get',
                        dataType: 'html',
                        beforeSend: function () {
                            layer.load(2);
                        },
                        complete: function () {
                            layer.closeAll('loading');
                        },
                        success: function (res) {
                            layer.open({
                                type: 1,
                                title:'添加用户',
                                skin: 'layui-layer-rim', //加上边框
                                area: ['560px', '560px'], //宽高
                                content: res,
                                cancel: function(index, layero){
                                    tableIns.reload({
                                        where: {}
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                    layer.close(index)
                                    return false;
                                }
                            });
                            return false;
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert('网络失败，请联系管理员', {icon: 2});
                        }
                    });
                    break;
                case 'deletes':
                    var data = checkStatus.data;
                    if(data.length == 0){
                        layer.msg('请选择删除的记录', {icon: 5}); return false;
                    }
                    layer.confirm('确定要删除吗?', {
                        btn: ['确定','取消'], //按钮
                        offset: '100px'
                    }, function(){
                        //获取选中的ID
                        var checkIdS = '';　//创建一个数组
                        $.each(data,function(k,value){
                            checkIdS += value.id + ',';
                        });

                        $.ajax({
                            url: '{:url("/finance/Salaryback/delete")}',
                            type: 'post',
                            dataType: 'json',
                            data: {checkIdS: checkIdS},
                            cache: false,
                            async: true,
                            beforeSend: function () {
                                layer.load(2);
                            },
                            complete: function () {
                                layer.closeAll('loading');
                            },
                            success: function (res) {
                                if(res.code == 1){
                                    layer.msg('删除成功', {icon: 1});
                                    tableIns.reload({
                                        where: {}
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                    return false;
                                }
                                layer.alert('删除失败', {icon: 2}); return false;
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert('网络失败，请联系管理员', {icon: 2});
                            }
                        });


                    }, function(){
                    });
                    break;
                case 'exportExcel':
                    var data = checkStatus.data;
//                    layer.msg('选中了：' + data.length + ' 个');
                    //获取选中的ID
                    var checkIdS = '';　//创建一个数组
                    $.each(data,function(k,value){
                        checkIdS += value.id + ',';
                    });
                    //导出文件
                function exportExcel(){
                    var name = $('#name').val();
                    var card_num = $('#card_num').val();
                    var form = $("<form>");
                    form.attr('style', 'display:none');
                    form.attr('target', '');
                    form.attr('method', 'post');
                    form.attr('action', '{:url("/finance/Salaryback/exportFile")}');

                    var input1 = $('<input>');
                    input1.attr('type', 'hidden');
                    input1.attr('name', 'name');
                    /* JSON.stringify($.serializeObject($('#searchForm'))) */
                    input1.attr('value', name);

                    var input3 = $('<input>');
                    input3.attr('type', 'hidden');
                    input3.attr('name', 'card_num');
                    input3.attr('value', card_num);

                    //选中的ID
                    var input4 = $('<input>');
                    input4.attr('type', 'hidden');
                    input4.attr('name', 'checkIdS');
                    input4.attr('value', checkIdS);


                    $('body').append(form);
                    form.append(input1);
                    form.append(input3);
                    form.append(input4);

                    form.submit();
                    form.remove();
                }
                    exportExcel();
                    break;
            };
        });
        //搜索重载表格
        $('#search-input').click(function () {
            var name = $('#name').val();
            var card_num = $('#card_num').val();
            tableIns.reload({
                where: { //设定异步数据接口的额外参数，任意设
                     name: name
                    , card_num: card_num
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        function uploadRender(){
            upload.render({
                elem: '#uploadExcel'
                , url: '{:url("/finance/Salaryback/uploadExcel")}' //改成您自己的上传接口
                , accept: 'file' //普通文件
                , done: function (res) {
                    if(res.code == 2){
                        layer.confirm('该文件已经导入', {
                            btn: ['覆盖导入','不覆盖导入'] //按钮
                            ,offset: '100px'
                        }, function(){
                            // layer.msg('的确很重要', {icon: 1});
                            //覆盖导入
                            $.ajax({
                                url: '{:url("/finance/Salaryback/getUploadFileData")}',
                                type: 'post',
                                dataType: 'json',
                                data: {file_id: res.data.file_id,type:0,old_file_id: res.data.old_file_id},
                                cache: false,
                                async: true,
                                beforeSend: function () {
                                    layer.load(2);
                                },
                                complete: function () {
                                    layer.closeAll('loading');
                                },
                                success: function (res) {
                                    if(res.code == 1){
                                        layer.msg('导入成功');
                                        window.top.frames['main'].location.href = '{:url("/finance/Salaryback/index")}';
                                        // uploadRender();
                                        tableIns.reload({
                                            where: {}
                                            , page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                        return false;
                                    }
                                    layer.alert('导入失败', {icon: 2});
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.alert('网络失败，请联系管理员', {icon: 2});
                                }
                            });
                        }, function(){
                            //不覆盖导入
                            $.ajax({
                                url: '{:url("/finance/Salaryback/getUploadFileData")}',
                                type: 'post',
                                dataType: 'json',
                                data: {file_id: res.data.file_id,type:1},
                                cache: false,
                                async: true,
                                beforeSend: function () {
                                    layer.load(2);
                                },
                                complete: function () {
                                    layer.closeAll('loading');
                                },
                                success: function (res) {
                                    if(res.code == 1){
                                        layer.msg('导入成功');
                                        window.top.frames['main'].location.href = '{:url("/finance/Salaryback/index")}';
                                        // uploadRender();
                                        tableIns.reload({
                                            where: {}
                                            , page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                        return false;
                                    }
                                    layer.alert('导入失败', {icon: 2});
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.alert('网络失败，请联系管理员', {icon: 2});
                                }
                            });
                            // layer.msg('也可以这样', {
                            //     time: 20000, //20s后自动关闭
                            //     btn: ['明白了', '知道了']
                            // });
                        });
                    }
                    if (res.code == 1) {
                        $.ajax({
                            url: '{:url("/finance/Index/getUploadFileData")}',
                            type: 'post',
                            dataType: 'json',
                            data: {file_id: res.data.file_id},
                            cache: false,
                            async: true,
                            beforeSend: function () {
                                layer.load(2);
                            },
                            complete: function () {
                                layer.closeAll('loading');
                            },
                            success: function (res) {
                                if(res.code == 1){
                                    layer.msg('导入成功');
                                    window.top.frames['main'].location.href = '{:url("/finance/Index/salary")}';
                                    // uploadRender();
                                    tableIns.reload({
                                        where: {}
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                    return false;
                                }
                                layer.alert('导入失败', {icon: 2});
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert('网络失败，请联系管理员', {icon: 2});
                            }
                        });
                    }
                    if (res.code == 0) {
                        layer.msg(res.msg,{icon: 5});
                    }

                }
            });
        }
        uploadRender();


//        //上传excel文件
//        upload.render({
//            elem: '#uploadExcel'
//            , url: '{:url("/finance/Index/uploadExcel")}' //改成您自己的上传接口
//            , accept: 'file' //普通文件
//            , done: function (res) {
//                if (res.code == 1) {
//                    $.ajax({
//                        url: '{:url("/finance/Index/getUploadFileData")}',
//                        type: 'post',
//                        dataType: 'json',
//                        data: {file_id: res.data.file_id},
//                        cache: false,
//                        async: true,
//                        beforeSend: function () {
//                            layer.load(2);
//                        },
//                        complete: function () {
//                            layer.closeAll('loading');
//                        },
//                        success: function (res) {
//                          if(res.code == 1){
//                              layer.msg('导入成功');
//                              tableIns.reload({
//                                  where: {}
//                                  , page: {
//                                      curr: 1 //重新从第 1 页开始
//                                  }
//                              });
//                              return false;
//                          }
//                            layer.alert('导入失败', {icon: 2});
//                        },
//                        error: function (XMLHttpRequest, textStatus, errorThrown) {
//                            layer.alert('网络失败，请联系管理员', {icon: 2});
//                        }
//                    });
//                }
//                if (res.code == 0) {
//                    layer.msg(res.msg,{icon: 5});
//                }
//
//            }
//        });

    });
</script>
</body>
</HTML>